registry=$1
project_name=$2
version=$3

imageName=${registry}${project_name}:${version}

echo $imageName

containerId=`nerdctl ps -a | grep ${project_name} | awk '{print $1}'`

echo $containerId

if [ "$containerId" != "" ]; then
    nerdctl stop $containerId
    nerdctl rm $containerId
fi

tag=`nerdctl images | grep ${project_name} | awk '{print $2}'`

echo $tag

if [[ "$tag" =~ "${version}" ]]; then
    nerdctl rmi $imageName
fi

nerdctl login --username=jim_hu --password=SXdx@0351! registry.cn-hangzhou.aliyuncs.com
nerdctl pull $imageName
